﻿using System;

class TextBetweenTagsToUppercase
{
    static void Main()
    {
        //Exercise 5.
        //You are given a text. Write a program that changes the text in all regions surrounded by the tags <upcase> and </upcase> to 
        //uppercase. The tags cannot be nested. Example:
        //We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.
        
        //The expected result:   We are living in a YELLOW SUBMARINE. We don't have ANYTHING else.

        //IF YOU'D LIKE, YOU MAY TYPE YOUR TEXT HERE:
        //Console.Write("Type the text: ");
        //string text = Console.ReadLine();
        
        string text = @"We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.";
        int startSearchIndex = 0;
        
        int startIndexUpperText = 0;
        int endIndexUpperText = 0;

        bool noString = false;
        string replaced = "";

        while (!noString)
        {
            if (text.IndexOf("<upcase>", startSearchIndex) != -1)
            {
                startIndexUpperText = text.IndexOf("<upcase>", startSearchIndex) + 8;
                startSearchIndex = text.IndexOf("<upcase>", startSearchIndex) + 1;
            }
            else
            {
                noString = true;
            }

            if (text.IndexOf("</upcase>", startSearchIndex) != -1)
            {
                endIndexUpperText = text.IndexOf("</upcase>", startSearchIndex);
                startSearchIndex = text.IndexOf("</upcase>", startSearchIndex) + 1;
            }
            else
            {
                noString = true;
            }
                        
            for (int i = startIndexUpperText; i < endIndexUpperText; i++)
            {
                replaced += text[i];
            }

            text = text.Replace(replaced, replaced.ToUpper());            
            replaced = "";
        }
        text = text.Replace("<upcase>", "");
        text = text.Replace("</upcase>", "");
        Console.WriteLine(text);
    }
}

